<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">客户名称：</label>
                  <div class="layui-input-inline">
                    <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                  </div>
                </div>
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" layui-form-keyDownSearch="true" lay-submit>查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
              <div class="query-rt"></div>
            </div>
          </div>
        </div>
        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button id="customersInfoBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
              <button id="fromLocalWarehouseBtnImport" class="layui-btn icon-btn color-reseda">
                <input id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx" />导入
              </button>
            </div>
            <div class="lay-btn-rt">
              <button id="fromLocalWarehouseBtnTemplate" class="layui-btn icon-btn">模板下载</button>
            </div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="customersInfoTable" lay-filter="customersInfoTable"></table>
    </div>
  </div>
</div>

<style>
  .width105 {
    width: 105px;
  }

  .borderNone {
    border: none;
  }

  /*导入*/
  .import {
    opacity: 0;
    position: absolute;
    width: 69px;
    height: 38px;
    margin-left: -10px;
  }
</style>
<!-- 表格操作列 -->
<script type="text/html" id="customersInfoTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">详情</a>

  <!-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a> -->
  <!--    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="due">尽调</a>-->
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="custContract">合同</a>
  <a class="layui-btn  layui-btn-xs" lay-event="contact">联系人</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="followRecord">跟进记录</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="customersInfoForm">
  <form lay-filter="customersInfoForm" id="customersInfoFormContent" class="layui-form model-form">
    <input name="id" type="hidden" />
    <input name="approverName" id="approverNameHidden" type="hidden" />
    <input name="salesmanName" id="salesmanNameHidden" type="hidden" />
    <div class="layui-col-xs12">
      <div class="layui-form-item">
        <label class="layui-form-label">客户类型</label>
        <div class="layui-input-block">
          <select name="customerType" id="customerType">
            <option value="">请选择客户类型</option>
            <option value="potential" selected>潜在客户</option>
            <option value="Intended">意向客户</option>
            <option value="formal">正式客户</option>
          </select>
        </div>
      </div>
    </div>
    <!--        <div class="layui-col-xs6">-->
    <!--            <div class="layui-form-item">-->
    <!--                <label class="layui-form-label">所属代理商</label>-->
    <!--                <div class="layui-input-block">-->
    <!--                    <select name="selAgtId" lay-search></select>-->
    <!--                </div>-->
    <!--            </div>-->
    <!--        </div>-->
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>客户名称</label>
        <div class="layui-input-block">
          <input name="customerName" placeholder="请输入客户名称" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>营业执照号</label>
        <div class="layui-input-block">
          <input name="licenseNo" placeholder="请输入营业执照号" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">省</label>
        <div class="layui-input-block">
          <input type="hidden" name="provinceName" id="provinceName" class="layui-input"/>
          <div class="detailBox">
            <select name="province" id="province" lay-filter="province"></select>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">市</label>
        <div class="layui-input-block">
          <input type="hidden" name="cityName" id="cityName" class="layui-input"/>
          <div class="detailBox">
            <select name="city" id="city" lay-filter="city"></select>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">区</label>
        <div class="layui-input-block">
          <input type="hidden" name="areaName" id="areaName" class="layui-input"/>
          <div class="detailBox">
            <select name="area" id="area" lay-filter="area"></select>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">详情地址</label>
        <div class="layui-input-block">
          <input name="address" placeholder="请输入详情地址" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>联系人姓名</label>
        <div class="layui-input-block">
          <input name="contactName" placeholder="请输入联系人姓名" type="text" class="layui-input" lay-verify="required" required />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>职务</label>
        <div class="layui-input-block">
          <select name="postId" id="postId" lay-filter="postId" lay-verify="required" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
          <input name="department" placeholder="请输入所属部门" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">名片</label>
        <div class="layui-input-block">
          <div id="btnUpload15" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件</div>
          <div id="btnUpload15_path" style="margin-left: 150px;line-height: 40px;"></div>
          <input id="btnUpload15_file" name="visitingCard" type="hidden" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>电话</label>
        <div class="layui-input-block">
          <input name="telephone" placeholder="请输入电话" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">微信号</label>
        <div class="layui-input-block">
          <input name="wechatNumber" placeholder="请输入微信号" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
          <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" />
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red">*</span>线索来源</label>
        <div class="layui-input-block">
          <select name="clueSourceId" id="clueSourceId" lay-filter="clueSourceId" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">推荐人</label>
        <div class="layui-input-block">
          <input name="referees" placeholder="请输入推荐人" type="text" class="layui-input" />
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">年用刀量</label>
        <div class="layui-input-inline">
          <input name="dosage" placeholder="请输入年用刀量" type="text" class="layui-input" />
        </div>
        <div class="layui-form-mid layui-word-aux">单位：万元</div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">业务员</label>
        <div class="layui-input-block">
          <select name="salesmanId" lay-filter="salesman" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-col-xs6">
      <div class="layui-form-item">
        <label class="layui-form-label">审批人</label>
        <div class="layui-input-block">
          <select name="approver" lay-filter="approver" lay-search></select>
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      <button class="layui-btn" lay-filter="customersInfoFormSubmit" lay-submit>保存</button>
    </div>
  </form>
</script>

<!--详情弹框-->
<script type="text/html" id="detailTable">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 潜在客户详细列表 -->
        <table class="layui-table" id="customersDetailTable" lay-filter="customersDetailTable"></table>
        <!-- 选项 -->
        <div class="layui-tab">
          <ul class="layui-tab-title">
            <li class="layui-this">客户基本信息</li>
            <li>客户联系人信息</li>
            <li>跟进记录</li>
            <li>客户线索信息</li>
          </ul>
          <div class="layui-tab-content">
            <!--客户基本信息-->
            <div class="layui-tab-item layui-show">
              <form lay-filter="customersDetailForm" class="layui-form model-form">
                <input name="id" type="hidden" />
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">企业名称</label>
                    <div class="layui-input-inline">
                      <input name="name" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">营业执照号</label>
                    <div class="layui-input-inline">
                      <input name="licenseNo" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">所在地址</label>
                    <div class="layui-input-inline">
                      <input name="addr" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">营业执照照片</label>
                    <div class="uploadImgStyle" id="licensePhoto">
                      <input type="hidden" name="licensePhoto" lay-verify="" data-name="营业执照照片" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">企业性质</label>
                    <div class="layui-input-inline">
                      <input name="subjectNatureDesc" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户所属分类</label>
                    <div class="layui-input-inline">
                      <input name="agentCategoryName" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">收款银行</label>
                    <div class="layui-input-inline">
                      <input name="bankName" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">收款银行户名</label>
                    <div class="layui-input-inline">
                      <input name="bankAccount" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">收款银行账号</label>
                    <div class="layui-input-inline">
                      <input name="bankCard" placeholder="" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6" style="height: 170px;">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">开户许可证</label>
                    <div class="uploadImgStyle" id="license">
                      <input type="hidden" name="openingPermit" lay-verify="" data-name="开户许可证" disabled />
                    </div>
                  </div>
                </div>

                <div class="layui-form-item text-right">
                  <button class="layui-btn" type="button" ew-event="closeDialog">返回</button>
                </div>
              </form>
            </div>

            <!--客户联系人信息-->
            <div class="layui-tab-item">
              <!-- 头部操作栏 -->
              <div class="layui-form lay-header">
                <div class="toolbar">
                  <div class="layui-form-item lay-query-content">
                    <div class="lay-query-box">
                      <div class="query-lt">
                        <div class="layui-inline">
                          <label class="layui-form-label w-auto">客户名称：</label>
                          <div class="layui-input-inline">
                            <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                          </div>
                        </div>
                        <div class="layui-inline">
                          <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                        </div>
                      </div>
                      <div class="query-rt"></div>
                    </div>
                  </div>
                </div>
                <div class="lay-btn-rows">
                  <div class="lay-btn-box">
                    <div class="lay-btn-lt">
                      <button id="contactInfoBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                  </div>
                </div>
              </div>
              <!-- 客户联系人表格 -->
              <table class="layui-table" id="contactInfoTable" lay-filter="contactInfoTable"></table>
            </div>

            <!--跟进记录-->
            <div class="layui-tab-item">
              <!-- 头部操作栏 -->
              <div class="layui-form lay-header">
                <div class="lay-btn-rows">
                  <div class="lay-btn-box">
                    <div class="lay-btn-lt">
                      <button id="customerFollowRecordBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                  </div>
                </div>
              </div>
              <!-- 表格 -->
              <table class="layui-table" id="customerFollowRecordTable" lay-filter="customerFollowRecordTable"></table>
            </div>
            <!--客户线索信息-->
            <div class="layui-tab-item">
              <form lay-filter="customerLeadsForm" class="layui-form model-form">
                <input name="id" type="hidden" />
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户录入渠道</label>
                    <div class="layui-input-inline">
                      <input name="agentName" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户录入人</label>
                    <div class="layui-input-inline">
                      <input name="agtCreatorName" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">客户录入电话</label>
                    <div class="layui-input-inline">
                      <input name="agtCreatorPhone" id="agtCreatorPhone" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">签单人</label>
                    <div class="layui-input-inline">
                      <input name="signer" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">签单人电话</label>
                    <div class="layui-input-inline">
                      <input name="signerPhone" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">所属服务专员</label>
                    <div class="layui-input-inline">
                      <select name="salesmanId" id="salesmanId" lay-filter="salesmanId" lay-verify="required" required lay-search></select>
                    </div>
                  </div>
                </div>
                <div class="layui-col-xs6">
                  <div class="layui-form-item">
                    <label class="layui-form-label width105">服务专员电话</label>
                    <div class="layui-input-inline">
                      <input name="salesmanPhone" id="salesmanPhone" type="text" class="layui-input borderNone" disabled />
                    </div>
                  </div>
                </div>
                <div class="layui-form-item text-right">
                  <button class="layui-btn" type="button" ew-event="closeDialog">返回</button>
                  <button class="layui-btn" id="customersLeadsUpdate" lay-filter="customersLeadsUpdate" lay-submit>保存</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>

<!--客户联系人div-->
<div id="lxr">
  <!--客户联系人-按钮弹窗-->
  <script type="text/html" id="contactHtml">
    <!-- 正文开始 -->
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form lay-header">
            <div class="toolbar">
              <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                  <div class="query-lt">
                    <div class="layui-inline">
                      <label class="layui-form-label w-auto">客户名称：</label>
                      <div class="layui-input-inline">
                        <input name="customerName" class="layui-input" type="text" placeholder="请输入客户名称" />
                      </div>
                    </div>
                    <div class="layui-inline">
                      <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    </div>
                  </div>
                  <div class="query-rt"></div>
                </div>
              </div>
            </div>
            <div class="lay-btn-rows">
              <div class="lay-btn-box">
                <div class="lay-btn-lt">
                  <button id="contactInfoBtnAdd2" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                </div>
              </div>
            </div>
          </div>
          <!-- 客户联系人表格 -->
          <table class="layui-table" id="contactInfoTable2" lay-filter="contactInfoTable"></table>
        </div>
      </div>
    </div>
  </script>

  <!-- 客户联系人-表格操作列 -->
  <script type="text/html" id="contactInfoTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
  </script>

  <!-- 客户联系人-表单弹窗 -->
  <script type="text/html" id="contactInfoForm">
    <form lay-filter="contactInfoForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">所属客户</label>
          <div class="layui-input-block">
            <select name="selCustomerId" lay-filter="selCustomerId" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>联系人姓名</label>
          <div class="layui-input-block">
            <input name="name" placeholder="请输入联系人姓名" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>电话</label>
          <div class="layui-input-block">
            <input name="telephone" placeholder="请输入电话" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">性别</label>
          <div class="layui-input-block">
            <select name="sex">
              <option value="">请选择性别</option>
              <option value="man">男</option>
              <option value="woman">女</option>
              <option value="other">未知</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>职务</label>
          <div class="layui-input-block">
            <select name="postId" id="contactPostId" lay-filter="postId" lay-verify="required" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">所属部门</label>
          <div class="layui-input-block">
            <input name="department" placeholder="请输入所属部门" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">微信号</label>
          <div class="layui-input-block">
            <input name="wechatNumber" placeholder="请输入微信号" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">邮箱</label>
          <div class="layui-input-block">
            <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">通讯地址</label>
          <div class="layui-input-block">
            <input name="mailAddress" placeholder="请输入通讯地址" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">排序</label>
          <div class="layui-input-block">
            <input name="sort" placeholder="" type="text" class="layui-input" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red"></span>联系人照片</label>
          <div id="btnUpload14" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件</div>
          <div id="btnUpload14_path" style="margin-left: 260px;line-height: 40px;"></div>
          <input id="btnUpload14_file" name="picture" type="hidden"/>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label">名片</label>
          <div class="layui-input-block">
            <div id="btnUpload16" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件</div>
            <div id="btnUpload16_path" style="margin-left: 150px;line-height: 40px;"></div>
            <input id="btnUpload16_file" name="visitingCard" type="hidden" />
          </div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
          <textarea name="remark" placeholder="请输入备注" maxlength="200" class="layui-textarea"></textarea>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="contactInfoFormSubmit" lay-submit>保存</button>
      </div>
    </form>
  </script>
</div>

<!--跟进记录-->
<div id="gjjl">
  <!-- 跟进记录-表格操作列 -->
  <script type="text/html" id="customerFollowRecordTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    {{# if(d.status =="pendingReview"){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="process">审核</a>
    {{# } }}
  </script>

  <!-- 跟进记录-按钮弹窗 -->
  <script type="text/html" id="followRecordHtml">
    <!-- 正文开始 -->
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-card-body">
          <!-- 头部操作栏 -->
          <div class="layui-form lay-header">
            <div class="toolbar">
              <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                  <div class="query-lt">
                    <div class="layui-inline">
                      <label class="layui-form-label w-auto">跟进客户：</label>
                      <div class="layui-input-inline">
                        <select name="followCustomer"></select>
                      </div>
                    </div>
                    <div class="layui-inline">
                      <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    </div>
                  </div>
                  <div class="query-rt"></div>
                </div>
              </div>
            </div>
            <div class="lay-btn-rows">
              <div class="lay-btn-box">
                <div class="lay-btn-lt">
                  <button id="customerFollowRecordBtnAdd2" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                </div>
              </div>
            </div>
          </div>
          <!-- 表格 -->
          <table class="layui-table" id="customerFollowRecordTable2" lay-filter="customerFollowRecordTable"></table>
        </div>
      </div>
    </div>
  </script>

  <!-- 跟进记录-表单弹窗 -->
  <script type="text/html" id="customerFollowRecordForm">
    <form lay-filter="customerFollowRecordForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">客户类型</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="customerType" id="followCustomerType" lay-filter="customerType" disabled="disabled">
              <option value="">请选择客户类型</option>
              <option value="potential">潜在客户</option>
              <option value="Intended">意向客户</option>
              <option value="formal">正式客户</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">跟进类型</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followType" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">跟进客户</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followCustomer" lay-filter="followCustomer" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">跟进对象</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followTarget" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">跟进方式</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followWay" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">跟进结果类型</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="followResult" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">产生费用</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <input name="cost" placeholder="请输入产生费用" type="text" class="layui-input" lay-verify="required" required />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">审批人</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <select name="approver" lay-filter="approver" lay-verify="required" required lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">跟进结果描述</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <textarea name="followDescribe" placeholder="请输入跟进结果描述" maxlength="200" class="layui-textarea" lay-verify="required"></textarea>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px">备注</label>
          <div class="layui-input-block" style="margin-left: 130px;">
            <textarea name="remark" placeholder="请输入备注" maxlength="200" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>
      <input name="approverName" id="followApproverName" type="hidden" />
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="customerFollowRecordFormSubmit" lay-submit>保存</button>
      </div>
    </form>
  </script>

  <!-- 跟进记录-详情表单弹窗 -->
  <script type="text/html" id="customerFollowRecordDetailForm">
    <form lay-filter="customerFollowRecordDetailForm" class="layui-form model-form">
      <input name="id" type="hidden" />
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">客户类型</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="customerType" class="selectDisabled" disabled="disabled">
              <option value="">请选择客户类型</option>
              <option value="potential">潜在客户</option>
              <option value="Intended">意向客户</option>
              <option value="formal">正式客户</option>
            </select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进类型</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="followType" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进客户</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="followCustomer" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进对象</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="followTarget" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进对象职务</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <input name="postName" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进对象电话</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <input name="telephone" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进方式</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="followWay" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进结果类型</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="followResult" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">产生费用</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <input name="cost" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">提交时间</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <input name="createTime" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">审批时间</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <input name="checkTime" type="text" class="layui-input selectDisabled" />
          </div>
        </div>
      </div>
      <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label width105">审批人</label>
          <div class="layui-input-block" style="width: 70%; margin-left: 135px;">
            <select name="approver" class="selectDisabled" lay-search></select>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label width105">跟进结果描述</label>
          <div class="layui-input-block" style="width: 85%; margin-left: 135px;">
            <textarea name="followDescribe" maxlength="200" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>
      <div class="layui-col-xs12">
        <div class="layui-form-item">
          <label class="layui-form-label width105">备注</label>
          <div class="layui-input-block" style="width: 85%; margin-left: 135px;">
            <textarea name="remark" id="followRemark" maxlength="200" class="layui-textarea"></textarea>
          </div>
        </div>
      </div>

      <div class="layui-form-item text-right">
        <button class="layui-btn" id="customerFollowRecordDetailFormSubmit" lay-filter="customerFollowRecordDetailFormSubmit" lay-submit>保存</button>
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
      </div>
    </form>
  </script>
</div>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "upload", "laytpl"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laytpl = layui.laytpl;
    const dataType = {};
    if ($("#intendedCustomersInfo").length > 0) {
      dataType.url = "intendedCustomersInfo";
    } else {
      dataType.url = "potentialCustomersInfo";
    }
    console.log("dataType", dataType);
    //导入excel
    $("#uploaderInput").on("change", function (e) {
      layer.load(2);
      var formData = new FormData();
      var files = e.target.files;
      let that = $(this);
      formData.append("file", files[0]);
      formData.append("name", files[0].name); //这个地方可以传递多个参数
      $.ajax({
        url: config.base + "enterprise/sell/admin/" + dataType.url + "/importExcel",
        data: formData,
        headers: { Authorization: "Bearer " + config.getToken() },
        type: "POST",
        processData: false,
        contentType: false,
        success: function (res) {
          layer.closeAll("loading");
          if (res.code == 200) {
            layer.msg(res.msg, { icon: 1 });
            // table.reload('humanResourcesTable');
            layer.closeAll("page");
            setTimeout((_) => {
              location.reload();
            }, 1000);
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
          that.val("");
        }
      });
    });
    // 模板下载
    $("#fromLocalWarehouseBtnTemplate").click(function () {
      window.location.href = config.base + "enterprise/sell/admin/'+dataType.url+'/template";
    });

    // 渲染表格
    var insTb = table.render({
      elem: "#customersInfoTable",
      url: config.base + "enterprise/sell/admin/" + dataType.url + "/list",
      toolbar: true,
      defaultToolbar: ["filter"],
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", title: "序号" },
          { field: "licenseNo", align: "center", title: "统一社会信用代码", width: 180 },
          { field: "customerName", align: "center", title: "客户名称" },
          {
            field: "region",
            align: "center",
            title: "所在区域",
            templet: function (d) {
              d.region = d.provinceName + "/" + d.areaName;
              return d.region;
            }
          },
          { field: "agentCategoryName", align: "center", title: "所属分类" },
          { field: "agentName", align: "center", title: "所属渠道" },
          { field: "contactName", align: "center", title: "客户代表" },
          { align: "center", title: "客户标签" },
          { field: "customerTypeDesc", align: "center", title: "客户状态" },
          { field: "createTime", align: "center", title: "合作日期", width: 160 },
          { align: "center", toolbar: "#customersInfoTableBar", title: "操作", width: 270 }
        ]
      ],
      done: function (res, curr, count) {
        //移除按钮
        var menuButton = config.getMenuButton(location.hash);
      }
    });

    // 工具条点击事件
    table.on("tool(customersInfoTable)", function (obj) {
      var data = obj.data;
      if (obj.event === "edit") {
        //修改
        showEditModel(data);
      } else if (obj.event === "del") {
        // 删除
        doDelete(obj);
      } else if (obj.event === "detail") {
        //详情
        showDetailModel(data);
      } else if (obj.event === "contact") {
        //联系人
        showContact(data);
      } else if (obj.event === "followRecord") {
        //跟进记录
        showFollowRecord(data);
      }
    });

    //验证
    form.verify({
      contactShot: function (value, item) {
        if (value === "") {
          return "请上传联系人照片";
        }
      }
    });

    //监听排序
    table.on("sort(customersInfoTable)", function (obj) {
      table.reload("customersInfoTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });
    // 重置搜索
    form.on("submit(resets)", (data) => {
      $(".lay-header").find("select").val("");
      $(".lay-header").find("input").val("");
      let field = data.field;
      for (let key in field) {
        field[key] = "";
      }
      insTb.reload({ where: field, page: { curr: 1 } }, "data");
    });

    // 添加按钮点击事件
    $("#customersInfoBtnAdd").click(function () {
      showEditModel();
    });

    // 显示编辑弹窗
    function showEditModel(data) {
      admin.open({
        type: 1,
        area: "1000px",
        offset: "65px",
        title: data ? "客户信息" : "添加客户信息",
        content: $("#customersInfoForm").html(),
        success: function () {
          if (data) {
            var option = $("form select[name='customerType']").find("option");
            layui.each(option, function (index, item) {
              if (data.customerType == item.text) {
                data.customerType = item.value;
              }
            });
          }

          //获取职务
          admin.req(
            "enterprise/sell/admin/customerContactPost/list",
            { limit: 999 },
            (res) => {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择职务", "postId", "name");
                if (data) {
                  $("#postId").val(data.postId);
                  form.render("select");
                }
              }
            },
            "get"
          );

          //获取线索来源
          admin.req(
            "enterprise/sell/admin/customerClueSource/list",
            { limit: 999 },
            (res) => {
              if (res.code == 200) {
                loadSelectHtml(res.data, "请选择", "clueSourceId", "name");
                if (data) {
                  $("#clueSourceId").val(data.clueSourceId);
                  form.render("select");
                }
              }
            },
            "get"
          );

          getUsers(data); //获取审批人/业务员
          form.on("select(approver)", function (data) {
            //审批人姓名
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: data.value },
              (res) => {
                if (res.code == "200") {
                  $("#approverNameHidden").val(res.data.nickname);
                }
              },
              "GET"
            );
          });
          form.on("select(salesman)", function (data) {
            //业务员姓名
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: data.value },
              (res) => {
                if (res.code == "200") {
                  $("#salesmanNameHidden").val(res.data.nickname);
                }
              },
              "GET"
            );
          });

          // getAgentInfo();//获取代理商

          //**设置禁止选择：**//
          $("#customerType").attr("disabled", "disabled");
          //$("#customerType").attr("style", "background-color: #EEEEEE;");//设为灰色

          form.val("customersInfoForm", data);
          // zzq无奈写成这样
          if (data && data.id) {
            admin.setFormDisable("#customersInfoFormContent", true);
            $("#provinceName").attr("type", "text");
            $("#cityName").attr("type", "text");
            $("#areaName").attr("type", "text");
            $(".detailBox").hide();
          }
          // 获取省区域信息
          admin.req(
            "enterprise/area/getProvinceList",
            {},
            function (res) {
              if (200 == res.code) {
                loadSelectHtml(res.data, "请选择省份", "province", "name");
              }
            },
            "POST",
            true
          );

          var selectArea = function (city) {
            admin.req(
              "enterprise/area/getAreaList?parentId=" + city,
              {},
              function (res) {
                layer.closeAll("loading");
                if (200 == res.code) {
                  loadSelectHtml(res.data, "请选择区/县", "area", "name");
                }
              },
              "POST"
            );
          };
          var selectCity = function (province) {
            admin.req(
              "enterprise/area/getCityList?parentId=" + province,
              {},
              function (res) {
                layer.closeAll("loading");
                if (200 == res.code) {
                  loadSelectHtml(res.data, "请选择市", "city", "name");
                }
              },
              "POST"
            );
          };

          form.on("select(province)", function (data) {
            $("#city").empty();
            $("#area").empty();
            // 获取市区域信息
            if (data.value != "") {
              selectCity(data.value);
            }
          });
          form.on("select(city)", function (data) {
            $("#area").empty();
            // 获取区县区域信息
            if (data.value != "") {
              selectArea(data.value);
            }
          });

          //上传名片
          uploadImg("btnUpload15", "btnUpload15_path", "btnUpload15_file");
          if (data && data.visitingCard) {
            $("#btnUpload15_path").html('<img src="' + data.visitingCard + '" style="height: 35px;" />');
          }

          // 表单提交事件
          form.on("submit(customersInfoFormSubmit)", function (d) {
            layer.load(2);
            admin.req(
              data ? "enterprise/sell/admin/" + dataType.url + "/update" : "enterprise/sell/admin/" + dataType.url + "/add",
              d.field,
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("customersInfoTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST"
            );
            return false;
          });
        }
      });
    }

    // 删除
    function doDelete(obj) {
      layer.confirm(
        "确定要删除吗？",
        {
          offset: "65px",
          skin: "layui-layer-admin"
        },
        function (i) {
          layer.close(i);
          layer.load(2);
          admin.req(
            "enterprise/sell/admin/" + dataType.url + "/" + obj.data.id,
            {},
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                obj.del();
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "DELETE"
          );
        }
      );
    }

    //显示详情弹窗
    function showDetailModel(data) {
      admin.open({
        type: 1,
        area: ["1480px", "800px"],
        title: "详情",
        content: $("#detailTable").html(),
        success: function () {
          getDetail(data);
        }
      });
    }

    //显示联系人弹窗
    function showContact(data) {
      admin.open({
        type: 1,
        area: ["1280px", "800px"],
        title: "联系人信息",
        content: $("#contactHtml").html(),
        success: function () {
          contactInfo(data);
        }
      });
    }

    //显示跟进记录弹窗
    function showFollowRecord(data) {
      admin.open({
        type: 1,
        area: ["1480px", "800px"],
        title: "跟进记录信息",
        content: $("#followRecordHtml").html(),
        success: function () {
          followRecordInfo(data);
        }
      });
    }

    //详情窗口
    function getDetail(data) {
      //渲染潜在客户详细信息
      table.render({
        elem: "#customersDetailTable",
        url: config.base + "enterprise/sell/admin/" + dataType.url + "/list?id=" + data.id,
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers" },
            { field: "licenseNo", align: "center", title: "统一信用编码", width: 180 },
            { field: "customerName", align: "center", title: "客户名称" },
            {
              field: "region",
              align: "center",
              title: "所在地",
              templet: function (d) {
                d.region = d.provinceName + "/" + d.areaName;
                return d.region;
              }
            },
            { field: "contactName", align: "center", title: "联系人" },
            {
              field: "contactWay",
              align: "center",
              title: "联系方式",
              templet: function (d) {
                if (d.telephone != null && d.telephone != "") {
                  return d.telephone;
                } else {
                  if (d.wechatNumber != null && d.wechatNumber != "") {
                    return d.wechatNumber;
                  }
                  if (d.email != null && d.email != "") {
                    return d.email;
                  }
                }
              }
            },
            { field: "agentName", align: "center", title: "渠道服务商" },
            { field: "salesmanName", align: "center", title: "业务员" },
            { field: "createTime", align: "center", title: "添加日期", width: 180 }
          ]
        ],
        done: function (res, curr, count) {
          //移除按钮
        }
      });
      // 客户基本信息
      admin.req(
        "enterprise/sell/admin/agent/list",
        { limit: 99999, status: "2,3" },
        (res) => {
          if (res.code == "200" && res.data.length > 0) {
            form.val("customersDetailForm", res.data[0]);
            if (res.data[0] && res.data[0].licensePhoto) {
              $("#licensePhoto").html(
                '<img src="' + res.data[0].licensePhoto + '" style="max-width: 196px"><input type="hidden" name="licensePhoto" value="' + res.data[0].licensePhoto + '" />'
              );
            }

            if (res.data[0] && res.data[0].openingPermit) {
              $("#license").html(
                '<img src="' + res.data[0].openingPermit + '" style="max-width: 196px"><input type="hidden" name="license" value="' + res.data[0].openingPermit + '" />'
              );
            }
            layer.photos({
              photos: ".uploadImgStyle",
              anim: 5
            });
          }
        },
        "GET"
      );
      //客户联系人信息
      contactInfo(data);
      //跟进记录
      followRecordInfo(data);
      //客户线索信息
      customerLeadsInfo(data);
    }

    //客户联系人信息
    function contactInfo(data) {
      var insTb = table.render({
        elem: "#contactInfoTable,#contactInfoTable2",
        url: config.base + "enterprise/sell/admin/contactInfo/list",
        where: { selCustomerId: data.id },
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers", title: "序号" },
            { field: "name", align: "center", title: "姓名" },
            { field: "telephone", align: "center", title: "电话", width: 130 },
            { field: "sexDesc", align: "center", title: "性别" },
            { field: "postName", align: "center", title: "职务" },
            { field: "department", align: "center", title: "所属部门" },
            { field: "email", align: "center", title: "邮箱", width: 170 },
            { field: "remark", align: "center", title: "备注" },
            { field: "createTime", align: "center", title: "创建时间", width: 180 },
            { align: "center", toolbar: "#contactInfoTableBar", title: "操作", width: 150 }
          ]
        ]
      });
      // 工具条点击事件
      table.on("tool(contactInfoTable)", function (obj) {
        var data = obj.data;
        if (obj.event === "edit") {
          //修改
          showContactEditModel(data);
        } else if (obj.event === "del") {
          // 删除
          doDelete(obj);
        }
      });

      //监听排序
      table.on("sort(contactInfoTable)", function (obj) {
        table.reload("contactInfoTable", {
          initSort: obj,
          where: {
            sort: obj.field,
            order: obj.type
          }
        });
      });

      // 搜索
      form.on("submit(formSubSearchLog)", function (data) {
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });

      // 添加按钮点击事件
      $("#contactInfoBtnAdd,#contactInfoBtnAdd2").click(function () {
        showContactEditModel(null, data.id);
      });

      // 显示联系人编辑弹窗
      function showContactEditModel(data, selCustomerId) {
        admin.open({
          type: 1,
          area: "820px",
          offset: "130px",
          title: data ? "修改客户联系人信息" : "添加客户联系人信息",
          content: $("#contactInfoForm").html(),
          success: function () {
            //获取职务
            admin.req(
              "enterprise/sell/admin/customerContactPost/list",
              { limit: 999 },
              (res) => {
                if (res.code == 200) {
                  loadSelectHtml(res.data, "请选择职务", "postId", "name");
                  if (data) {
                    $("#contactPostId").val(data.postId);
                    form.render("select");
                  }
                }
              },
              "get"
            );
            form.val("contactInfoForm", data);

            // 获取客户数据
            admin.req(
              "enterprise/sell/admin/" + dataType.url + "/list",
              { limit: 9999 },
              function (res) {
                if (res.code == 200) {
                  var html = '<option value="">请选择客户</option>';
                  for (var k = 0; k < res.data.length; k++) {
                    html += '<option value="' + res.data[k].id + '">' + res.data[k].customerName + "</option>";
                  }
                  $("form select[name='selCustomerId']").html(html);
                  form.render("select");
                  if (data && data.selCustomerId) {
                    form.val("contactInfoForm", data);
                  }
                  if (selCustomerId) {
                    form.val("contactInfoForm", { selCustomerId: selCustomerId });
                  }
                } else {
                  layer.msg("获取客户失败", { icon: 2, time: 1000 });
                }
              },
              "GET"
            );

            //上传联系人照片
            upload.render({
              elem: "#btnUpload14",
              url: config.upload_url + "upload?path=" + img_path,
              data: {},
              accept: "file",
              exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
              headers: { authorization: "Bearer " + config.getToken() },
              done: function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg || "上传成功", { icon: 1 });
                  var imagUrl = res.data.url;
                  $("#btnUpload14_path").html('<img src="' + imagUrl + '" style="height: 35px;" />');
                  $("#btnUpload14_file").val(imagUrl);
                } else if (res.code == 502) {
                  return location.replace("admin/login.html");
                } else {
                  layer.msg(res.msg || "上传失败", { icon: 2 });
                }
              }
            });

            if (data && data.picture) {
              $("#btnUpload14_path").html('<img src="' + data.picture + '" style="height: 35px;" />');
            }

            //上传名片
            upload.render({
              elem: "#btnUpload16",
              url: config.upload_url + "upload?path=" + img_path,
              data: {},
              accept: "file",
              exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
              headers: { authorization: "Bearer " + config.getToken() },
              done: function (res) {
                if (res.code == 200) {
                  layer.msg(res.msg || "上传成功", { icon: 1 });
                  var imagUrl = res.data.url;
                  $("#btnUpload16_path").html('<img src="' + imagUrl + '" style="height: 35px;" />');
                  $("#btnUpload16_file").val(imagUrl);
                } else if (res.code == 502) {
                  return location.replace("admin/login.html");
                } else {
                  layer.msg(res.msg || "上传失败", { icon: 2 });
                }
              }
            });
            if (data && data.visitingCard) {
              $("#btnUpload16_path").html('<img src="' + data.visitingCard + '" style="height: 35px;" />');
            }

            // 表单提交事件
            form.on("submit(contactInfoFormSubmit)", function (d) {
              layer.load(2);
              admin.req(
                data ? "enterprise/sell/admin/contactInfo/update" : "enterprise/sell/admin/contactInfo/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("contactInfoTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
              return false;
            });
          }
        });
      }
    }

    //跟进记录
    function followRecordInfo(data) {
      // 渲染表格
      var insTb = table.render({
        elem: "#customerFollowRecordTable,#customerFollowRecordTable2",
        url: config.base + "enterprise/sell/admin/customerFollowRecord/list",
        where: { customerType: 1, followCustomer: data.id },
        page: true,
        cellMinWidth: 100,
        cols: [
          [
            { type: "numbers" },
            { field: "customerTypeDesc", align: "center", title: "客户类型" },
            { field: "followTypeName", align: "center", title: "跟进类型" },
            { field: "followCustomerName", align: "center", title: "跟进客户", width: 140 },
            { field: "followTargetName", align: "center", title: "跟进对象" },
            { field: "followWayName", align: "center", title: "跟进方式" },
            { field: "followResultName", align: "center", title: "跟进结果" },
            { field: "cost", align: "center", title: "产生费用" },
            { field: "followDescribe", align: "center", title: "跟进结果" },
            { field: "approverName", align: "center", title: "审批人" },
            { field: "statusDesc", align: "center", title: "状态" },
            { field: "createTime", align: "center", title: "创建时间", width: 160 },
            { align: "center", toolbar: "#customerFollowRecordTableBar", title: "操作", width: 150 }
          ]
        ]
      });

      // 工具条点击事件
      table.on("tool(customerFollowRecordTable)", function (obj) {
        var data = obj.data;
        var type = 0; //0-详情，1-审核
        if (obj.event === "edit") {
          //修改
          showEditModel(data);
        } else if (obj.event === "del") {
          // 删除
          doDelete(obj);
        } else if (obj.event === "detail") {
          //详情
          showDetail(data, type);
        } else if (obj.event === "process") {
          //审核
          type = 1;
          showDetail(data, type);
        }
      });

      // 搜索
      //获取客户数据
      admin.req(
        "enterprise/sell/admin/customersInfo/getCustomerByType",
        {},
        function (res) {
          if (res.code == 200) {
            loadSelectHtml(res.data, "请选择跟进客户", "followCustomer", "customerName");
          } else {
            layer.msg("获取客户失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );

      form.on("submit(formSubSearchLog)", function (data) {
        insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      });

      // 添加按钮点击事件
      $("#customerFollowRecordBtnAdd,#customerFollowRecordBtnAdd2").click(function () {
        showEditModel(null, true);
      });

      //详情弹窗
      function showDetail(data, type) {
        admin.open({
          type: 1,
          area: "860px",
          title: type === 1 ? "审核跟进记录" : "跟进记录详情",
          content: $("#customerFollowRecordDetailForm").html(),
          success: function () {
            if (data) {
              var option = $("form select[name='customerType']").find("option");
              layui.each(option, function (index, item) {
                if (data.customerType == item.text) {
                  data.customerType = item.value;
                }
              });
            }

            form.val("customerFollowRecordDetailForm", data);

            getCompany(data); // 获取客户数据

            getContactInfo(data); // 获取客户联系人

            getFollowType(data); // 获取跟进类型

            getFollowWay(data); // 获取跟进方式

            getFollowResultType(data); // 获取跟进结果类型

            getUsers(data); // 获取审批人

            $(".selectDisabled").attr("disabled", "disabled");
            //$(".selectDisabled").attr("style", "background-color: #EEEEEE;");//设为灰色
            //$(".selectDisabled").attr("style", "border: none;");

            if (type == 0) {
              $("#followRemark").attr("disabled", true);
              $("#customerFollowRecordDetailFormSubmit").hide(); //提交按钮隐藏
            } else if (type == 1) {
              $("#followRemark").attr("disabled", false);
              $("#customerFollowRecordDetailFormSubmit").show(); //提交按钮显示

              form.on("submit(customerFollowRecordDetailFormSubmit)", function (d) {
                layer.load(2);
                admin.req(
                  "enterprise/sell/admin/customerFollowRecord/audit",
                  d.field,
                  function (res) {
                    if (res.code == 200) {
                      layer.closeAll("loading");
                      layer.msg(res.msg, { icon: 1 });
                      table.reload("customerFollowRecordTable");
                      layer.closeAll("page");
                    } else {
                      layer.msg(res.msg, { icon: 2 });
                    }
                  },
                  "PUT"
                );
              });
            }
          }
        });
      }

      // 显示跟进记录编辑弹窗
      function showEditModel(data, istrue) {
        admin.open({
          type: 1,
          area: "760px",
          offset: "110px",
          title: data ? "修改跟进记录管理" : "添加跟进记录管理",
          content: $("#customerFollowRecordForm").html(),
          success: function () {
            if (data) {
              var option = $("form select[name='customerType']").find("option");
              layui.each(option, function (index, item) {
                if (data.customerType == item.text) {
                  data.customerType = item.value;
                }
              });
            }
            if (istrue) {
              let val = "";
              let utl = window.location.href;
              if (utl.indexOf("customersInfo") > -1) {
                val = "formal";
              } else if (utl.indexOf("intendedCustomersInfo") > -1) {
                val = "Intended";
              } else if (utl.indexOf("potentialCustomersInfo") > -1) {
                val = "potential";
              }
              $("#followCustomerType").val(val);
              var followCoustomer = {};
              followCoustomer.value = val;
              getCompany(followCoustomer); // 获取客户数据
            }
            form.val("customerFollowRecordForm", data);
            form.on("select(customerType)", function (data) {
              getCompany(data); // 获取客户数据
            });
            form.on("select(followCustomer)", function (data) {
              getContactInfo(data); // 获取客户联系人
            });

            getFollowType(data); // 获取跟进类型

            getFollowWay(data); // 获取跟进方式

            getFollowResultType(data); // 获取跟进结果类型

            getUsers(data); // 获取审批人
            form.on("select(approver)", function (data) {
              //审批人姓名
              admin.req(
                "user/admin/user/getUserInfoByUserId",
                { userId: data.value },
                (res) => {
                  if (res.code == "200") {
                    $("#followApproverName").val(res.data.nickname);
                  }
                },
                "GET"
              );
            });

            // 表单提交事件
            form.on("submit(customerFollowRecordFormSubmit)", function (d) {
              layer.load(2);
              admin.req(
                data ? "enterprise/sell/admin/customerFollowRecord/update" : "enterprise/sell/admin/customerFollowRecord/add",
                d.field,
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    table.reload("customerFollowRecordTable");
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                data ? "PUT" : "POST"
              );
              return false;
            });
          }
        });
      }
    }

    //客户线索信息
    function customerLeadsInfo(data) {
      //展示客户线索信息
      admin.req(
        "enterprise/sell/admin/customersInfo/getLeadList",
        { id: data.id },
        (res) => {
          if (res.code == "200" && res.data.length > 0) {
            form.val("customerLeadsForm", res.data[0]);

            //客户录入人电话
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: res.data[0].agtCreator },
              (res2) => {
                if (res2.code == "200") {
                  $("#agtCreatorPhone").val(res2.data.phone);
                }
              },
              "GET"
            );

            //服务专员电话
            admin.req(
              "user/admin/user/getUserInfoByUserId",
              { userId: res.data[0].salesmanId },
              (salesmanRes) => {
                if (salesmanRes.code == "200") {
                  $("#salesmanPhone").val(salesmanRes.data.phone);
                }
              },
              "GET"
            );
          }
        },
        "GET"
      );

      //下拉框-获取所属服务专员
      getUsers(data);
      form.on("select(salesmanId)", function (data) {
        admin.req(
          "user/admin/user/getUserInfoByUserId",
          { userId: data.value },
          (res) => {
            if (res.code == "200") {
              $("#salesmanPhone").val(res.data.phone);
            }
          },
          "GET"
        );
      });

      //修改服务专员
      $("#customersLeadsUpdate").click(function () {
        var salesmanId = $("#salesmanId").val();

        admin.req(
          "enterprise/sell/admin/customersInfo/updateSalesman",
          {
            id: data.id,
            salesmanId: salesmanId
          },
          function (res) {
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
              table.reload("detailTable");
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
          },
          "PUT"
        );
      });
    }

    // 获取客户数据
    function getCompany(data) {
      admin.req(
        "enterprise/sell/admin/customersInfo/getCustomerByType",
        { customerTypeName: data.value },
        function (res) {
          if (res.code == 200) {
            loadSelectHtml(res.data, "请选择客户", "followCustomer", "customerName");

            if (data && data.followCustomer) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            loadSelectHtml(res.data, "请选择", "followCustomer", "customerName");
            layer.msg(res.msg, { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 获取客户联系人
    function getContactInfo(data) {
      admin.req(
        "enterprise/sell/admin/contactInfo/list",
        { selCustomerId: data.value },
        function (res) {
          if (res.code == 200) {
            loadSelectHtml(res.data, "请选择客户联系人", "followTarget", "name");

            if (data && data.followTarget) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取联系人失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 获取跟进类型
    function getFollowType(data) {
      admin.req(
        "enterprise/sell/admin/customerFollowType/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择跟进类型</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].code + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='followType']").html(html);
            form.render("select");
            if (data && data.followType) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取跟进类型失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    // 获取跟进方式
    function getFollowWay(data) {
      admin.req(
        "enterprise/sell/admin/customerFollowWay/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择跟进方式</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].code + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='followWay']").html(html);
            form.render("select");
            if (data && data.followWay) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取跟进方式失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取跟进结果类型
    function getFollowResultType(data) {
      admin.req(
        "enterprise/sell/admin/customerFollowResultType/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择跟进结果</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].code + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='followResult']").html(html);
            form.render("select");
            if (data && data.followResult) {
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取跟进结果类型失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取审批人/业务员
    function getUsers(data) {
      admin.req(
        "user/admin/user/list",
        { limit: 9999 },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择审批人/业务员</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].id + '">' + res.data[k].username + "</option>";
            }
            $("form select[name='approver']").html(html);
            $("form select[name='salesmanId']").html(html);
            form.render("select");
            if (data) {
              $("#salesmanId").val(data.salesmanId);
              form.render("select");
              form.val("customerFollowRecordForm", data);
              form.val("customerFollowRecordDetailForm", data);
            }
          } else {
            layer.msg("获取审批人失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    //获取代理商
    function getAgentInfo() {
      admin.req(
        "enterprise/sell/admin/agent/list",
        { limit: 9999, status: "2,3" },
        function (res) {
          if (res.code == 200) {
            var html = '<option value="">请选择代理商</option>';
            for (var k = 0; k < res.data.length; k++) {
              html += '<option value="' + res.data[k].id + '">' + res.data[k].name + "</option>";
            }
            $("form select[name='selAgtId']").html(html);
            form.render("select");
            /* if(data && data.selAgtId){
                         form.val('customerFollowRecordForm', data);
                     }*/
          } else {
            layer.msg("获取代理商失败", { icon: 2, time: 1000 });
          }
        },
        "GET"
      );
    }

    /**
     * 加载地址HTML
     * @param data 下拉菜单数据
     * @param tips select 默认提示
     * @param htmltarget html要插入的位置
     * @param name  下拉框需要显示值的属性
     */
    function loadSelectHtml(data, tips, htmltarget, name) {
      let html = " <option value>" + tips + "</option>";
      if (!data || data == null) {
        return;
      }
      for (let i = 0; i < data.length; i++) {
        html += `<option value='${data[i].id}'>${data[i][name]}</option>`;
      }
      $("[name='" + htmltarget + "']").html(html);
      form.render("select");
    }

    // 上传图片
    function uploadImg(_elem, pathId, inputId) {
      upload.render({
        elem: "#" + _elem,
        url: config.upload_url + "upload",
        data: {},
        accept: "file",
        exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
        headers: { Authorization: "Bearer " + config.getToken() },
        done: function (res) {
          if (res.code == 200) {
            layer.msg(res.msg || "上传成功", { icon: 1 });
            let imagUrl = res.data.url;
            $("#" + pathId).html('<img src="' + imagUrl + '" style="height: 35px;"/>');
            $("#" + inputId).val(imagUrl);
          } else if (res.code == 502) {
            return location.replace("admin/login.html");
          } else {
            layer.msg(res.msg || "上传失败", { icon: 2 });
          }
        }
      });
    }
  });
</script>
